#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-01-16 15:41:31

import threading
import time


def run(n):
    semaphore.acquire()
    time.sleep(1)
    print('run the thread: %s\n' % n)
    semaphore.release()


if __name__ == '__main__':
    num = 0
    semaphore = threading.BoundedSemaphore(3)
    for i in xrange(20):
        t = threading.Thread(target=run, args=(i,))
        t.start()

while threading.active_count() != 1:
    # print('thread is running')
    pass
else:
    print('-- all thread done--')
    print(num)
